<div class="fanbox">
    <h3>编辑产品</h3>
    <form id="add_form" action="do.php?action=update" method="post">
		<?php
			include_once ("connect.php");
			$id = $_GET['id'];
			$sql = "select * from products where id='".$id."'";
			//echo $sql;
			$p1 = mysql_query($sql);
			$rows = mysql_fetch_array($p1);
			
			// if(count($rows)==0){
				// echo $rows;
				// echo $id;
				// die('error id:'.$id);				
			// }
			
			$product_1=$rows;
			//echo $product_1;
			
		?>
        <table width="100%" cellpadding="0" cellspacing="0" class="post_table">
			<input type="hidden" name="id" value="<?php echo $product_1['id']; ?>"/>
            <tr>
                <td width="30%" align="right">产品名称：</td>
                <td><input type="text" class="input2" name="pro_title" maxlength="30" value="<?php echo $product_1['title']; ?>"/></td>
            </tr>            
            <tr>
                <td align="right">主屏尺寸：</td>
                <td>
                <select name="size">
				    <?php
						$pingmus=array(
							"3.2英寸 480x360像素",
                            "3.5英寸 960x640像素",
                            "4英寸 854x480像素",
							"4.3英寸 800x480像素",
						);
						
						$cur_pm_size = $product_1['size'];
						foreach ($pingmus as $size){
							if($size==$cur_pm_size){
								echo '<option value="'.$size.'" selected>'.$size.'</option>';
							}
							else{
								echo '<option value="'.$size.'">'.$size.'</option>';
							}
						}
					?>                    
                </select>
                </td>
            </tr>
            <tr>
                <td align="right">操作系统：</td>
                <td>
                <select name="os">
					<?php
						$systems=array();	
						$query2=mysql_query('select distinct os from products');
						while($row=mysql_fetch_array($query2)){
							$systems[]=$row[0];
						}
						
						$cur_os = $product_1['os'];
						foreach($systems as $size){
							if($size==$cur_os){
								echo '<option value="'.$size.'" selected>'.$size.'</option>';
							}
							else{
								echo '<option value="'.$size.'">'.$size.'</option>';
							}
						}
					?>                   
                </select>
                </td>
            </tr>
            <tr>
                <td align="right">电池容量：</td>
                <td><input type="text" class="input2" style="width:100px" name="charge" maxlength="30" value="<?php echo $product_1['charge']; ?>"/> mAh</td>
            </tr>
            <tr>
                <td align="right">价格(￥)：</td>
                <td><input type="text" class="input2" style="width:100px" name="price" id="price" maxlength="30" value="<?php echo $product_1['price']; ?>"/> 元</td>
            </tr>
            <tr>
                <td height="60">&nbsp;</td>
                <td><input type="submit" class="btn" value="提交"/> <input type="button" class="btn" value="取消" onclick="$.fancybox.close();" /></td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript">
$(function(){
	$('#add_form').ajaxForm({
		beforeSubmit: validate,
		success: function(msg){
			if(msg==1){
				$.fancybox.close();
				$().message("成功修改！");
				$("#list").trigger("reloadGrid");
			}else{
				alert(msg);
			}
		}
	}); 
});
function validate(formData, jqForm, options) {  
    for (var i=0; i < formData.length; i++) { 
        if (!formData[i].value) { 
			$().message("请输入完整相关信息");
            return false; 
        } 
    } 
	$().message("正在提交...");
}
</script>